package com.apps.apicontroller;

import com.apps.common.enums.ClientType;
import com.apps.common.model.po.ApiResult;
import com.apps.globals.advent.model.po.KupaAdvent;
import com.apps.globals.advent.service.IKupaAdventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@Api(description = "广告管理全局接口")
@RestController
@RequestMapping("/api/advent")
public class AdventApiController
{

    @Autowired
    private IKupaAdventService adventService;

    @ApiOperation(value="添加广告位",notes = "用于添加广告位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "广告位的名字",  required = true,dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "key", value = "广告位的key",required = true,dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "width_height_rate", value = "广告位的宽度比例,是比列不是宽度",required = true,dataType = "float", paramType = "query"),
            @ApiImplicitParam(name = "client_type", value = "客户端类型",required = true,dataType = "string",  defaultValue = "PC,WAP", paramType = "query")
    })
    @PostMapping("/addAdvent")
    public ApiResult<String> updateImg(@RequestParam(name = "name") String name,
                                       @RequestParam(name = "key") String key,
                                       @RequestParam(name = "width_height_rate") Float width_height_rate,
                                       @RequestParam(name = "client_type") String client_type)
    {
        ApiResult<String> result=new ApiResult<>();
        adventService.addAdvent(name,key,width_height_rate, ClientType.valueOf(client_type));
        return result.success("添加成功");
    }

    @ApiOperation(value="给广告位添加广告",notes = "用于添加广告图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "advent_id", value = "广告位id",required = true,dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "广告的名字",  required = true,dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "url", value = "广告的key",required = true,dataType = "string", paramType = "query")
    })
    @PostMapping("/addAdventItem")
    public ApiResult<String> updateImg(@RequestParam(name = "advent_id") Integer advent_id,
                                       @RequestParam(name = "name") String name,
                                       @RequestParam(name = "url") String url,
                                       @RequestParam(value = "image") MultipartFile image)
    {
        ApiResult<String> result=new ApiResult<>();
        adventService.addAdventItem(advent_id,name,image,url);
        return result.success("添加成功");
    }
}
